﻿<UserControl x:Class="tomenglertde.ResXManager.View.Visuals.ConfigurationEditorView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" d:DesignHeight="600"
             xmlns:model="urn:ResXManager.Model"
             xmlns:converters="clr-namespace:tomenglertde.ResXManager.View.Converters"
             xmlns:properties="clr-namespace:tomenglertde.ResXManager.View.Properties"
             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
             xmlns:dgx="urn:tom-englert.de/DataGridExtensions"
             xmlns:globalization="clr-namespace:System.Globalization;assembly=mscorlib"
             xmlns:toms="urn:TomsToolbox"
             xmlns:system="clr-namespace:System;assembly=mscorlib"
             xmlns:visuals="clr-namespace:tomenglertde.ResXManager.View.Visuals"
             xmlns:themes="clr-namespace:tomenglertde.ResXManager.View.Themes"
             xmlns:infrastructure="urn:ResXManager.Infrastructure"
             xmlns:styles="urn:ResXManager.Styles"
             d:DataContext="{d:DesignInstance visuals:ConfigurationEditorViewModel}">
  <UserControl.Resources>

    <toms:ConfirmedCommandConverter x:Key="SortNodesByKeyCommandConverter" Executing="SortNodesByKeyCommandConverter_Executing" Error="CommandConverter_Error" />

    <Style TargetType="GroupBox" x:Key="GroupStyle" BasedOn="{StaticResource {x:Static styles:ResourceKeys.GroupBoxStyle}}">
      <Setter Property="HeaderTemplate">
        <Setter.Value>
          <DataTemplate>
            <ContentPresenter Content="{Binding}" TextElement.FontWeight="Bold" />
          </DataTemplate>
        </Setter.Value>
      </Setter>
      <Setter Property="Grid.IsSharedSizeScope" Value="True" />
      <Setter Property="Focusable" Value="False" />
    </Style>

    <Style x:Key="EmumSelectorItemContainerStyle" TargetType="ListBoxItem">
      <Setter Property="Focusable" Value="False" />
      <Setter Property="Template">
        <Setter.Value>
          <ControlTemplate TargetType="ListBoxItem">
            <RadioButton Margin="0,2" IsChecked="{Binding IsSelected, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
                         Content="{TemplateBinding Content, Converter={x:Static toms:ObjectToDisplayNameConverter.Default}}"
                         ToolTip="{TemplateBinding Content, Converter={x:Static toms:ObjectToDescriptionConverter.Default}}"
                         Style="{DynamicResource {x:Static styles:ResourceKeys.RadioButtonStyle}}"
                         Focusable="True" />
          </ControlTemplate>
        </Setter.Value>
      </Setter>
    </Style>

    <themes:ResourceLocator x:Key="ResourceLocator" />

  </UserControl.Resources>

  <ScrollViewer Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" Width="800" HorizontalAlignment="Left" VerticalScrollBarVisibility="Auto">
    <StackPanel Margin="10">
      <GroupBox Header="{x:Static properties:Resources.ConfigurationScopeHeader}"
                Style="{StaticResource GroupStyle}"
                Visibility="{Binding Configuration.IsScopeSupported, Converter={x:Static toms:BooleanToVisibilityConverter.Default}}">
        <Control Focusable="False">
          <Control.Template>
            <ControlTemplate>
              <Border x:Name="Background" Background="Yellow">
                <TextBlock x:Name="Text" Margin="10" TextWrapping="Wrap" Text="{x:Static properties:Resources.EditDefaultConfigurationNotification}" Foreground="Black" />
              </Border>
              <ControlTemplate.Triggers>
                <DataTrigger Binding="{Binding Configuration.Scope}" Value="{x:Static model:ConfigurationScope.Solution}">
                  <Setter TargetName="Background" Property="Background" Value="Orange" />
                  <Setter TargetName="Text" Property="Text" Value="{x:Static properties:Resources.EditSolutionConfigurationNotification}" />
                </DataTrigger>
              </ControlTemplate.Triggers>
            </ControlTemplate>
          </Control.Template>
        </Control>
      </GroupBox>

      <GroupBox Header="{x:Static properties:Resources.Configuration_General}" Style="{StaticResource GroupStyle}">
        <StackPanel Margin="10">
          <StackPanel Orientation="Horizontal">
            <TextBlock Text="{x:Static properties:Resources.NeutralResourceLanguageHeader}" VerticalAlignment="Center" />
            <Decorator Width="5" />
            <ComboBox Width="175" ItemsSource="{Binding Source={x:Static Member=model:ResourceManager.SpecificCultures}}"
                      SelectedItem="{Binding Configuration.NeutralResourcesLanguage}" Style="{DynamicResource {x:Static styles:ResourceKeys.ComboBoxStyle}}">
              <ComboBox.ItemTemplate>
                <DataTemplate DataType="globalization:CultureInfo">
                  <StackPanel Orientation="Horizontal">
                    <Image Stretch="None" Source="{Binding Converter={x:Static converters:CultureToImageSourceConverter.Default}}" />
                    <Decorator Width="5" />
                    <TextBlock Text="{Binding Path=DisplayName}" VerticalAlignment="Center" />
                  </StackPanel>
                </DataTemplate>
              </ComboBox.ItemTemplate>
            </ComboBox>
          </StackPanel>
        </StackPanel>
      </GroupBox>

      <Decorator Height="5" />

      <GroupBox Header="{x:Static properties:Resources.Configuration_LoadSaveHeader}" Style="{StaticResource GroupStyle}">
        <Grid Margin="10" KeyboardNavigation.TabNavigation="Local">
          <StackPanel>
            <CheckBox IsChecked="{Binding Configuration.SaveFilesImmediatelyUponChange}" TabIndex="0"
                      Style="{DynamicResource {x:Static styles:ResourceKeys.CheckBoxStyle}}"
                      Content="{x:Static properties:Resources.SaveFilesImmediatelyUponChange}" />
            <Decorator Height="10" />
            <CheckBox IsChecked="{Binding Configuration.SortFileContentOnSave}" TabIndex="0"
                      Style="{DynamicResource {x:Static styles:ResourceKeys.CheckBoxStyle}}"
                      Content="{x:Static properties:Resources.SortNodesByKey}" />
            <Decorator Height="5" />
            <StackPanel Orientation="Horizontal">
              <Decorator Width="22" />
              <TextBlock Text="{x:Static properties:Resources.SortBy}" VerticalAlignment="Center" />
              <Decorator Width="8" />
              <ComboBox Width="175" ItemsSource="{Binding Source={x:Type system:StringComparison}, Converter={x:Static toms:EnumToValuesConverter.Default}}"
                        SelectedItem="{Binding Configuration.ResXSortingComparison}" Style="{DynamicResource {x:Static styles:ResourceKeys.ComboBoxStyle}}" />
            </StackPanel>
          </StackPanel>
          <Button Padding="5,2" TabIndex="1" HorizontalAlignment="Right" VerticalAlignment="Bottom"
                  Content="{x:Static properties:Resources.SortAllFilesNow}"
                  Command="{Binding SortNodesByKeyCommand, Converter={StaticResource SortNodesByKeyCommandConverter}}"
                  Style="{DynamicResource {x:Static styles:ResourceKeys.ButtonStyle}}" />
        </Grid>
      </GroupBox>

      <Decorator Height="5" />

      <GroupBox Header="{x:Static properties:Resources.Configuration_FileCreationHeader}" Style="{StaticResource GroupStyle}">
        <StackPanel Margin="10" KeyboardNavigation.TabNavigation="Local">
          <CheckBox IsChecked="{Binding Configuration.AutoCreateNewLanguageFiles}" Content="{x:Static properties:Resources.AutoCreateNewLanguageFiles}" Style="{DynamicResource {x:Static styles:ResourceKeys.CheckBoxStyle}}" />
          <Decorator Height="5" />
          <CheckBox IsChecked="{Binding Configuration.ConfirmAddLanguageFile}" Content="{x:Static properties:Resources.ConfirmAddLanguage}" Style="{DynamicResource {x:Static styles:ResourceKeys.CheckBoxStyle}}" />
        </StackPanel>
      </GroupBox>

      <Decorator Height="5" />

      <GroupBox Header="{x:Static properties:Resources.Configuration_ExcelExportModeHeader}" Style="{StaticResource GroupStyle}">
        <ListBox Margin="10" BorderThickness="0" Background="Transparent"
                 ItemsSource="{Binding Source={x:Type model:ExcelExportMode}, Converter={x:Static toms:EnumToValuesConverter.Default}}"
                 SelectedItem="{Binding Configuration.ExcelExportMode}"
                 ItemContainerStyle="{StaticResource EmumSelectorItemContainerStyle}" />
      </GroupBox>

      <Decorator Height="5" />

      <GroupBox Header="{x:Static properties:Resources.Configuration_DuplicateKeyHandling}" Style="{StaticResource GroupStyle}">
        <ListBox Margin="10" BorderThickness="0" Background="Transparent"
                 ItemsSource="{Binding Source={x:Type model:DuplicateKeyHandling}, Converter={x:Static toms:EnumToValuesConverter.Default}}"
                 SelectedItem="{Binding Configuration.DuplicateKeyHandling}"
                 ItemContainerStyle="{StaticResource EmumSelectorItemContainerStyle}" />
      </GroupBox>

      <Decorator Height="5" />

      <GroupBox Header="{x:Static properties:Resources.Diagnostics}" Style="{StaticResource GroupStyle}">
        <CheckBox Margin="10"
                  Style="{StaticResource {x:Static styles:ResourceKeys.CheckBoxStyle}}"
                  Content="{x:Static properties:Resources.ShowPerformanceTraces}"
                  IsChecked="{Binding Configuration.ShowPerformanceTraces}"/>
      </GroupBox>

      <Decorator Height="5" />

      <GroupBox Header="{x:Static properties:Resources.DetectCodeReferences_Header}" Style="{StaticResource GroupStyle}">
        <DataGrid ItemsSource="{Binding Configuration.CodeReferences.Items}"
                  AutoGenerateColumns="False" CanUserReorderColumns="False" CanUserResizeRows="False"
                  Style="{DynamicResource {x:Static styles:ResourceKeys.DataGridStyle}}"
                  Margin="10" MinHeight="50" MaxHeight="250" MinWidth="700">
          <DataGrid.Columns>
            <DataGridTextColumn Header="{x:Static properties:Resources.FileExtensions}" Binding="{Binding Extensions}" Width="2*" />
            <DataGridTextColumn Header="{x:Static properties:Resources.RegularExpression}" Binding="{Binding Expression}" Width="5*" />
            <DataGridCheckBoxColumn Header="{x:Static properties:Resources.CaseSensitive}" Binding="{Binding IsCaseSensitive}" Width="*" />
            <DataGridTextColumn Header="{x:Static properties:Resources.CommentToken}" Binding="{Binding SingleLineComment}" Width="2*" />
          </DataGrid.Columns>
          <i:Interaction.Behaviors>
            <dgx:ExtendedStarSizeBehavior ResourceLocator="{StaticResource ResourceLocator}" />
          </i:Interaction.Behaviors>
        </DataGrid>
      </GroupBox>

      <Decorator Height="5" />

      <GroupBox Header="{x:Static properties:Resources.SourceFileExclusionFilters_Header}" Style="{StaticResource GroupStyle}">
          <DataGrid ItemsSource="{Binding Configuration.SourceFileExclusionFilters.Items}"
              AutoGenerateColumns="False" CanUserReorderColumns="False" CanUserResizeRows="False"
              Style="{DynamicResource {x:Static styles:ResourceKeys.DataGridStyle}}"
              Margin="10" MinHeight="50" MaxHeight="250" MinWidth="700">
              <DataGrid.Columns>
                  <DataGridTextColumn Header="{x:Static properties:Resources.RegularExpression}" Binding="{Binding Expression}" Width="5*" />
              </DataGrid.Columns>
              <i:Interaction.Behaviors>
                  <dgx:ExtendedStarSizeBehavior ResourceLocator="{StaticResource ResourceLocator}" />
              </i:Interaction.Behaviors>
          </DataGrid>
      </GroupBox>

      <ItemsControl toms:VisualComposition.RegionId="{x:Static infrastructure:RegionId.Configuration}">
        <ItemsControl.ItemTemplate>
          <DataTemplate>
            <StackPanel>
              <Decorator Height="5" />
              <GroupBox Header="{Binding Converter={x:Static toms:ObjectToDisplayNameConverter.Default}}" Style="{StaticResource GroupStyle}">
                <ContentControl Content="{Binding}" Margin="10" />
              </GroupBox>
            </StackPanel>
          </DataTemplate>
        </ItemsControl.ItemTemplate>
      </ItemsControl>

    </StackPanel>
  </ScrollViewer>
</UserControl>